package com.taotao.enums.annotation;

import com.fasterxml.jackson.annotation.JacksonAnnotationsInside;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.taotao.enums.jackson.EnumFieldSerializer;
import com.taotao.enums.validate.EnumFieldValidator;
import com.taotao.enums.BaseEnum;

import javax.validation.Constraint;
import javax.validation.Payload;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
 * <p>
 * 标注VO字段对应的枚举类.可用于常见类型和普通字符串、逗号分割的字符串，也可用于数组和集合
 * </p>
 *
 * @author youbeiwuhuan
 * @version 1.0.0
 * @date 2022/3/14 18:05
 */
@Inherited
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER})
@JacksonAnnotationsInside
@JsonSerialize(using = EnumFieldSerializer.class)
@Constraint(validatedBy = EnumFieldValidator.class)
public @interface EnumField {
    Class<? extends BaseEnum> value();


    /**
     * 分隔符,多个值用逗号隔开的场景
     *
     * @return
     */
    String separator() default "";

    //--------------------以下是校验用-----------------------------------------------------
    String message() default "";

    Class<?>[] groups() default {};

    Class<? extends Payload>[] payload() default {};
}
